package com.hlingsoft.kkh.action;

import com.hlingsoft.kkh.util.Common;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by selbylei on 2015/5/18.
 */
public class Test {

    public static void main(String[] args) throws Exception {

        ArrayList<Integer> list = new ArrayList<Integer>(){{add(1); add(2);add(11);add(12);add(14);}};

        List<Integer> integers = random(list);
        for (Integer integer:integers){
            System.out.println(integer);
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = sdf.parse("2015-07-02 00:00:00");
        Date now = new Date();

        System.out.println(diffTime(date, now)/60);

    }




    public static String ListToString(List<Integer> integerList) {
        String interestIds = "";
        for (int i = 0; i < 2; i++) {
            if (i < integerList.size() - 1) {
                interestIds += integerList.get(i).toString() + ',';
            } else {
                interestIds += integerList.get(i).toString();
            }
        }
        return interestIds;
    }


    public static List<Integer> random(List<Integer> send){

        int temp1,temp2,temp3;
        Random r = new Random();
        for(int i=0;i<send.size();i++) //随机交换send.length次
        {
            temp1 = Math.abs(r.nextInt())%(send.size()-1); //随机产生一个位置
            temp2 = Math.abs(r.nextInt())%(send.size()-1); //随机产生另一个位置
            if(temp1 != temp2)
            {

                temp3=send.get(temp1);
                send.set(temp1,send.get(temp2));
                send.set(temp2,temp3);
            }
        }
        return send;
    }


    public static String diff(String strDate, String pattern){
        String ret = "";
        try{
            Date now = new Date();

            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            Date tmp = sdf.parse(String.valueOf(now));

            if(tmp.after(now)){
                return "时间超过当前时间";
            }
            long s = (now.getTime() - tmp.getTime()) / 1000;
            long count = 0;
            if((count = s / (3600 * 24 * 365)) > 0){
                ret = count + "年前";
            }else if((count = s / (3600 * 24 * 30)) > 0){
                ret = count + "月前";
            }else if((count = s / 3600 * 24) > 0){
                ret = count + "天前";
            }else if((count = s / 3600) > 0){
                ret = count + "小时前";
            }else if((count = s / 60) > 0){
                ret = count + "分钟前";
            }else{
                ret = "刚刚";
            }
        }catch (Exception e) {
        }

        return ret;
    }


    public static  long diffTime(Date d1,Date d2){
        long s = (d2.getTime()-d1.getTime()) /1000;
        return s;
    }

}
